package com.runtu.types.design.framework.link.model2.chain;

import com.runtu.types.design.framework.link.model2.handler.ILogicHandler;

/**
 * @ClassName BusinessLinkedList
 * @Description 业务链路 因为需要执行整个链路 所以要遍历一下整个链路
 *这个方法就是一个一个结点往后执行直到为null为止，或者是返回一个对象为止，一条链路上并不是所有结点都要遍历到。
 *
 * @date 2025/8/7 16:58
 * @Version 1.0
 */
public class BusinessLinkedList<T,D,R> extends LinkedList<ILogicHandler<T,D,R>> implements ILogicHandler<T,D,R> {


    public BusinessLinkedList(String name){super(name);}

    @Override
    public R apply(T requestParameter, D dynamicContext) throws Exception {
        Node<ILogicHandler<T,D,R>> current = this.first;

        do{
            ILogicHandler<T,D,R> item=current.item;
            R apply = item.apply(requestParameter, dynamicContext);
            if(apply != null){
                return apply;
            }
            current = current.next;
        }while (null != current);

        return null;
    }
}
